<template>
  <a-modal
    v-model:visible="props.visible"
    @ok="handleOk"
    @cancel="handleCancel"
  >
    <template #title> 新增 </template>
    <div class="index">
      <a-form
        ref="formRef"
        :model="form"
        auto-label-width
        :style="{ width: '800px' }"
      >
        <a-form-item field="groupName" label="名称">
          <a-input v-model="form.groupName" />
        </a-form-item>
        <a-form-item field="url" label="排序">
          <a-input-number v-model="form.orderNo" />
        </a-form-item>
        <a-form-item field="isDefault" label="是否默认">
          <a-switch
            v-model="form.isDefault"
            :checked-value="1"
            :unchecked-value="2"
          />
        </a-form-item>
      </a-form>
    </div>
  </a-modal>
</template>
<script setup lang="ts">
import { FlowGroup } from '@/apis/flowGroup/type';
import clonedeep from 'lodash.clonedeep';

const props = withDefaults(
  //参数说明
  defineProps<{
    data?: FlowGroup;
    visible?: boolean;
  }>(),
  {
    visible: false
  }
);
const emit = defineEmits(['update:visible', 'save']);
const handleOk = () => {
  emit('save', form.value);
  close();
};
const handleCancel = () => {
  close();
};
const close = () => {
  emit('update:visible', false);
};
const form = ref<FlowGroup>({});
watch(
  () => props.data,
  () => {
    if (!props.data) return;
    form.value = clonedeep(props.data);
  }
);
const formRef = ref();
</script>
<style lang="less" scoped>
.index {
  display: flex;
  justify-content: center;
  width: 100%;
}
</style>
